package com.innoking.docsys.doc.service.impl;

import com.innoking.docsys.doc.dao.cluster.ClusterCmsJudItemMapper;
import com.innoking.docsys.doc.dao.cluster.ClusterCmsSinItemMapper;
import com.innoking.docsys.doc.dto.CmsJudItem;
import com.innoking.docsys.doc.dto.CmsSinItem;
import com.innoking.docsys.doc.service.GetOriginalService;
import org.apache.commons.lang.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @ClassName GetOriginalServiceImpl
 * @Description TODO
 * @Author wr
 * @Date 2019/9/9 000909:56
 */
@Service
public class GetOriginalServiceImpl implements GetOriginalService {

    Logger logger= LoggerFactory.getLogger(GetOriginalServiceImpl.class);

    @Autowired
    private ClusterCmsJudItemMapper clusterCmsJudItemMapper;

    @Autowired
    private ClusterCmsSinItemMapper clusterCmsSinItemMapper;

    @Override
    public String viewOriginal(String id, String type) {
        logger.info("***获取原文Service入参：id="+id+",type="+type);
        if(StringUtils.isBlank(id) || StringUtils.isBlank(type)){ return null; }
        String url =null;
        if("volItem".equals(type)){
            //卷内件
            CmsJudItem cmsJudItem = clusterCmsJudItemMapper.selectByPrimaryKey(Long.valueOf(id));
            if(cmsJudItem!=null){
                url = cmsJudItem.getItemStr2();
            }
        }else if ("sinItem".equals(type)){
            //单件
            CmsSinItem cmsSinItem = clusterCmsSinItemMapper.selectByPrimaryKey(Long.valueOf(id));
            if(cmsSinItem !=null){
                url = cmsSinItem.getItemStr2();
            }
        }else {
          return  url;
        }
        return url;
    }
}
